package com.hycreate.platform.modules.crm.information;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hycreate.platform.modules.crm.project.ProjectService;
import com.hycreate.platform.modules.sys.entity.User;

@Controller
@RequestMapping(value="${adminPath}/information/deptAndEmp")
public class DeptAndEmpQuery {
	ObjectMapper mapper = new ObjectMapper();
	@Autowired
	private ProjectService projectService;
	/**
	 * 查询所有的部门
	 * @param project
	 * @param model
	 * @return
	 */
	
//	@RequestMapping(value="findDept")
//	public void findDept(HttpServletResponse response)throws IOException {
//		System.out.println("findDept  come in ..............");
//		List<Office> dept = projectService.findAllDept();
//		String deptJson = mapper.writeValueAsString(dept);
//
//	    response.setContentType("application/json;charset=utf-8");
//		response.getWriter().print(deptJson);
//	}

	/**
	 * 根据部门查询部门下所有员工
	 * @param request
	 * @param response
	 * @param model
	 * @param redirectAttributes
	 * @throws IOException
	 */
	@RequestMapping(value="finduser")
	public void finduser(String deptId,HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		  
			String deptIds = request.getParameter("deptId");
			List<User> user = projectService.findUser(deptIds);
		    
			String customersJson = mapper.writeValueAsString(user);
			
		    response.setContentType("application/json;charset=utf-8");
			response.getWriter().print(customersJson);
		  
	}
}
